package com.itheima.mapper;

import com.itheima.domain.Classes;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface ClassesMapper {

    @Select("select * from classes")
    @Results({
            // 封装了班级基本信息
            @Result(column = "cid", property = "cid",id = true),
            @Result(column = "cname", property = "cname"),

            // 封装学生信息
            @Result(
                    property = "students",
                    javaType = List.class,
                    column = "cid",        // 根据学生表cid字段的值，去查询班级表
                    many = @Many(select = "com.itheima.mapper.StudentMapper.findByCid")    // 根据学生cid字段的值,调用ClassesMapper接口findById去查询
            )
    })
    public List<Classes> findAllClasses();
}
